﻿<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit"/>
    <title>用户登录</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="shortcut icon" href="favicon.ico"/>
    <link rel="stylesheet" href="css/font-awesome.min.css">
    <link rel="stylesheet" href="css/bootstrap.min.css"/>
    <link rel="stylesheet" href="css/layui.css"/>
    <link rel="stylesheet" href="css/console.css">
    <link rel="stylesheet" href="css/animate.css">
    <link rel="stylesheet" href="css/login.css?v=1.0">


</head>

<body>

<div class="login-container full-height">

    <!-- 动态云层动画 开始 -->
    <div class="clouds-container">
        <div class="clouds clouds-footer"></div>
        <div class="clouds"></div>
        <div class="clouds clouds-fast"></div>
    </div>
    <!-- 动态云层动画 结束 -->

    <!-- 顶部导航条 开始 -->
    <div class="header">
        <span class="title notselect">
            欢迎登录 在线测试通信 <sup>1.00</sup>
        </span>
        <ul>
            <!--<li class="notselect"><a href="javascript:void(0)" target="_blank">帮助</a></li>-->
            <li class="notselect">
                <a href="http://sw.bos.baidu.com/sw-search-sp/software/4bcf5e4f1835b/ChromeStandalone_54.0.2840.99_Setup.exe">
                    <b>推荐使用谷歌浏览器</b>
                </a>
            </li>
        </ul>
    </div>
    <!-- 顶部导航条 结束 -->

    <!-- 页面表单主体 开始 -->
    <div class="container" style="top:50%;margin-top:-300px">
        <form onsubmit="return false;" data-time="0.001" data-auto="true" method="post"
              class="content layui-form animated fadeInDown">
            <div class="people">
                <div class="tou"></div>
                <div id="left-hander" class="initial_left_hand transition"></div>
                <div id="right-hander" class="initial_right_hand transition"></div>
            </div>
            <ul>
                <li>
                    <input  name="username" type="text"  autofocus="autofocus" autocomplete="off" class="login-input username"
                           title="请输入4位及以上的字符" placeholder="请输入账号"/>
                </li>
                <li>

                    <input  name="password" type="password"  autofocus="autofocus" autocomplete="off" class="login-input password"
                           title="请输入4位及以上的字符" placeholder="请输入密码"/>
                </li>
                <li class="text-center">
                    <button type="button" class="layui-btn "  onclick="login()">登录</button>
                    <button type="button"  class="layui-btn " onclick="toregister()">注册</button>
                    <!--<a style="position:absolute;display:block;right:0" href="javascript:void(0)">忘记密码？</a>-->
                </li>
            </ul>
        </form>
    </div>
    <!-- 页面表单主体 结束 -->

    <!-- 底部版权信息 开始 -->
    <div class="footer notselect"> 出自老陈的博客</div>
    <!-- 底部版本信息 结束 -->

</div>
<!-- scripts -->

<script src="plugins/jquery/jquery.min.js"></script>
<script src="dist/js/md5.js"></script>
<script src="dist/js/common.js?v=1.3"></script>
<script src="dist/js/util.js?v=1.3"></script>

<script>
    function login(){
        $.ajax({
            type: "post",
            url: ApiUrl+"api/ws/login",
            dataType: "json",
            data: {"username":$("input[name='username']").val(),"password":$("input[name='password']").val(),"client":"wap"},
            // xhrFields:{
            //     withCredentials:true
            // },
            //crossDomain:true,// 这两个参数要在后端需要设置withCredentials，跨域要指定域名，withCredentials:true
            beforeSend: function(xhr) {
                // var timestamp = Date.parse(new Date())/1000;
                var timestamp =  getCurrentTime()
                var jsonStr ={"appkey":"sys-server","ts":timestamp,"username":$("input[name='username']").val(),"password":$("input[name='password']").val(),"client":"wap"};
                sign = createSign(jsonStr);
                xhr.setRequestHeader("appkey", appkey);
                xhr.setRequestHeader("ts", timestamp);
                xhr.setRequestHeader("sign", sign);

            },
            error: function (e) {
                alert("登录超时，请重新登录");

            },
            success: function (res) {
                if(res.code==200 ){
                    console.log(res)
                    alert("登录成功");
                    util.addcookie("token",res.data.token)
                    util.addcookie("userInfo",JSON.stringify(res.data))
                    util.addcookie("userId",res.data.id)
                    window.location.href="index.html";
                    return;
                }else{
                    alert(res.msg);
                }

            }
        });
    }
    function toregister() {
        location.href="register.html"
    }
</script>

</body>

</html>